package org.jing.ext.pdf.itextpdf;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.pdf.BaseFont;
import org.jing.core.util.ClassUtil;
import org.jing.core.util.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2021-02-04 <br>
 */
@SuppressWarnings({ "UnusedReturnValue", "unused", "WeakerAccess" }) public class DataList {
    List<DataRow> dataRowList;

    public DataList() {
        dataRowList = new ArrayList<>();
    }

    public DataList add(DataRow dataRow) {
        dataRowList.add(dataRow);
        return this;
    }

    public DataList add(String key) {
        dataRowList.add(new DataRow(key));
        return this;
    }

    public DataList add(String key, String value) {
        dataRowList.add(new DataRow(key, value));
        return this;
    }

    public DataList add(String key, String value, BaseFont fontStyle, BaseColor fontColor, float fontSize) {
        dataRowList.add(new DataRow(key, value, fontStyle, fontColor, fontSize));
        return this;
    }

    public DataList putAll(Map<String, ?> params) {
        if (null != params && params.size() != 0) {
            for (Map.Entry<String, ?> entry: params.entrySet()){
                add(entry.getKey(), ClassUtil.cast2String(entry.getValue()));
            }
        }
        return this;
    }

    public List<DataRow> getList() {
        return dataRowList;
    }
}
